import vue from "@vitejs/plugin-vue";
import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import https from 'https'

// 1、引入 vue3 setup 语法糖 给组件起名字的插件
import VueSetupExtend from "vite-plugin-vue-setup-extend";
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), VueSetupExtend()],
  // 配置服务相关
  server: {
    host: "localhost",
    port: 8088,
    open: true,
    proxy: {
      // 反向代理
      "/v1": {
        target: "https://sync.koukoutu.com/",
        changeOrigin: true,
        secure: false,
        protocolRewrite: 'https',
        // cookieDomainRewrite: 'localhost:8080',
        rewrite: (path) => path.replace(/^\/v1/, "/v1")
      },
      "/api": {
        target: "https://www.koukoutu.com",
        changeOrigin: true,
        secure: false,
        protocolRewrite: 'https',
        cookieDomainRewrite: 'localhost:8080',
        rewrite: (path) => path.replace(/^\/api/, "/api"),
      },
    },
  },
  resolve: {
    // 配置路径别名
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
      "@c": fileURLToPath(new URL("./src/components", import.meta.url)),
      "@s": fileURLToPath(new URL("./src/stores", import.meta.url)),
      "@u": fileURLToPath(new URL("./src/utils", import.meta.url)),
      "@a": fileURLToPath(new URL("./src/api", import.meta.url)),
      "@v": fileURLToPath(new URL("./src/view", import.meta.url)),
    },
  },
});
